<%@ page import="com.touzi.utils.MyHTTPUtils" %>
<%@ page import="com.touzi.constants.MobileCons" %>
<%@ page import="com.touzi.constants.DbCons" %>
<%@ page import="org.apache.ibatis.session.SqlSessionFactory" %>
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="com.touzi.mapper.UserMapper" %>
<%@ page import="com.touzi.beans.dbs.users.User" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="com.touzi.mapper.SysconfigMapper" %><%--
  Created by IntelliJ IDEA.
  User: w7851
  Date: 2018/5/16
  Time: 7:49
  申请提现页面
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%
    Cookie usercookie = MyHTTPUtils.getCookieByName(request, MobileCons.COOKIE_USERNAME);
    String userphone = usercookie.getValue();
    SqlSession sqlSession = ((SqlSessionFactory) application.getAttribute(DbCons.DB_FACTORY)).openSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    SysconfigMapper sysconfigMapper=sqlSession.getMapper(SysconfigMapper.class);

    User user = userMapper.findUserByDhmw(userphone).get(0);
    String cantixian=sysconfigMapper.findConfBykey("cantixian");

    sqlSession.close();

    if (!cantixian.equals("yes")){
        String msg = "系统异常，请联系客服!!";
        response.sendRedirect("/msg.jsp?msg=" + URLEncoder.encode(msg, "utf-8"));
        return;
    }

    if (user.frozen.equals("yes") ) {
        String msg = "账户存在异常，已被系统冻结，请联系客服!";
        response.sendRedirect("/msg.jsp?msg=" + URLEncoder.encode(msg, "utf-8"));
        return;
    }

    request.setAttribute("user", user);
%>

<!DOCTYPE html>
<!-- 查询用户数据并填充 -->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>申请提现</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>

    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>

    <script src="/js/jquery-3.3.1.min.js"></script>
    <link rel="stylesheet" href="/css/ydui.css">
    <script src="/js/ydui.flexible.js"></script>
    <style type="text/css">
        .xuanzed {
            color: #E8574E;
        }

        .errortip {
            font-size: 14px;
            margin: 4px;
            display: none;
        }

        .haserror {
            color: red;
        }

    </style>
</head>
<body>
</body>
<div class="g-flexview">
    <header class="m-navbar  navbar-fixed">
        <a onclick="goback()" class="navbar-item">
            <i class="back-ico"></i>
        </a>
        <div class="navbar-center"><span class="navbar-title">个人中心</span></div>
    </header>


    <div class="g-scrollview" style="margin-top: 0.9rem;margin-bottom: 0.9rem">

        <form action="/mobile" method="post">
            <input name="method" value="dotixian" style="display: none">
            <input name="user" value="${user.dianhua}" style="display: none">
            <div class="m-celltitle" style="margin-top: 16px">您的账户可用提款${user.keyong}元，最低提款1元</div>
            <div class="m-cell">
                <div class="cell-item">
                    <div class="cell-left">提款金额：</div>
                    <div class="cell-right"><input id="tikuanjin" name="money" type="number" step="0.01"
                                                   class="cell-input" placeholder="请输入提款金额" autocomplete="off"/></div>
                </div>

                <div class="cell-item">
                    <div class="cell-left">支付宝：</div>
                    <div class="cell-right"><input type="text" class="cell-input" placeholder="请输入支付宝账户"
                                                   value="${user.zhifubao}" name="aliaccount"
                                                   autocomplete="off"/></div>
                </div>

                <div class="cell-item">
                    <div class="cell-left">用户密码：</div>
                    <div class="cell-right"><input id="tixianpasswd" type="password" class="cell-input"
                                                   placeholder="请输入用户密码" name="passwd"
                                                   autocomplete="off"/></div>
                </div>

                <div class="cell-item">
                    <div class="cell-right">
                        <input type="text" name="code" id="code" class="cell-input" placeholder="请输入验证码"
                               autocomplete="off">
                        <img src="/mobile?method=getyzm" style="width: 150px;height: 40px;margin-top: 8px"
                             onclick="changeImg()">
                    </div>
                </div>

            </div>

            <div class="errors" style="">
                <p id="errorjiner" class="haserror errortip">金额有误</p>
                <p id="errormima" class="haserror errortip">用户密码错误</p>
                <p id="zhengzaitix" class="errortip">正在请求，请稍后……</p>
            </div>

            <div style="padding: 0 16px">
                <input type="submit" class="btn-block btn-primary" value="确认提款"></input>
            </div>
        </form>

    </div>
</div>
<script>
    function goback() {
        history.go(-1);
    }

    function changeImg() {
        var imgSrc = $("img");
        var src = "/mobile?method=getyzm&t=" + (new Date().getTime());
        console.log(src);
        imgSrc.attr("src", src);
    }

    $("form").data("submit", 0);

    $("form").submit(function () {
        var user =${user.dianhua};
        var tikuanjin = $("#tikuanjin");
        var tixianpasswd = $("#tixianpasswd");
        var code = $("#code");
        var value = Number($("#tikuanjin").val());

        var result = false;
        var jiner = false;

        if (isNaN(value) || value >${user.keyong} || value < 1) {
            $("#errorjiner").addClass("haserror").show().html("提示: 输入的金额有误");
            jiner = false;
        } else {
            $("#errorjiner").hide().removeClass("haserror");
            jiner = true;
        }

        $.ajax(
            {
                type: "POST",
                async: false,
                url: "/mobile",
                data: {
                    "method": "verifytixian",
                    "phone": ${user.dianhua},
                    "passwd": tixianpasswd.val(),
                    "code": code.val(),
                    "jiner": tikuanjin.val()
                },
                success: function (data) {
                    console.log(data);
                    var correct = "ok";
                    if (data == correct) {
                        result = true;
                        $("#errormima").hide().removeClass("haserror");
                    } else {
                        $("#errormima").addClass("haserror").show().html(data);
                        result = false;
                    }
                }
            }
        );

        if (result && jiner) {
            $("#zhengzaitix").show();
            $("#errormima").hide().removeClass("haserror");
            $("#errorjiner").hide().removeClass("haserror");
        } else {
            return false;
        }

    });

    $("#tikuanjin").blur(function () {
        var value = Number($(this).val());
        console.log(value);
        console.log(${user.keyong});
        if (isNaN(value) || value >${user.keyong} || value < 1) {
            $("#errorjiner").addClass("haserror").show().html("提示: 输入的金额有误");
            return;
        } else {
            $("#errorjiner").hide().removeClass("haserror");
        }
    });

</script>
</html>
